package com.zj.osm.entity.db;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.zj.osm.entity.greendao.Multimedia;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "MULTIMEDIA".
*/
public class MultimediaDao extends AbstractDao<Multimedia, Long> {

    public static final String TABLENAME = "MULTIMEDIA";

    /**
     * Properties of entity Multimedia.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property MultimediaId = new Property(1, String.class, "multimediaId", false, "MULTIMEDIA_ID");
        public final static Property PointId = new Property(2, Long.class, "pointId", false, "POINT_ID");
        public final static Property Name = new Property(3, String.class, "name", false, "NAME");
        public final static Property Path = new Property(4, String.class, "path", false, "PATH");
    }

    private Query<Multimedia> point_MultimediaListQuery;

    public MultimediaDao(DaoConfig config) {
        super(config);
    }
    
    public MultimediaDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"MULTIMEDIA\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"MULTIMEDIA_ID\" TEXT," + // 1: multimediaId
                "\"POINT_ID\" INTEGER," + // 2: pointId
                "\"NAME\" TEXT," + // 3: name
                "\"PATH\" TEXT);"); // 4: path
        // Add Indexes
        db.execSQL("CREATE UNIQUE INDEX " + constraint + "IDX_MULTIMEDIA_MULTIMEDIA_ID ON \"MULTIMEDIA\"" +
                " (\"MULTIMEDIA_ID\" ASC);");
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"MULTIMEDIA\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, Multimedia entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String multimediaId = entity.getMultimediaId();
        if (multimediaId != null) {
            stmt.bindString(2, multimediaId);
        }
 
        Long pointId = entity.getPointId();
        if (pointId != null) {
            stmt.bindLong(3, pointId);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(4, name);
        }
 
        String path = entity.getPath();
        if (path != null) {
            stmt.bindString(5, path);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, Multimedia entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String multimediaId = entity.getMultimediaId();
        if (multimediaId != null) {
            stmt.bindString(2, multimediaId);
        }
 
        Long pointId = entity.getPointId();
        if (pointId != null) {
            stmt.bindLong(3, pointId);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(4, name);
        }
 
        String path = entity.getPath();
        if (path != null) {
            stmt.bindString(5, path);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public Multimedia readEntity(Cursor cursor, int offset) {
        Multimedia entity = new Multimedia( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // multimediaId
            cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2), // pointId
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4) // path
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, Multimedia entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setMultimediaId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setPointId(cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2));
        entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setPath(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(Multimedia entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(Multimedia entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(Multimedia entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "multimediaList" to-many relationship of Point. */
    public List<Multimedia> _queryPoint_MultimediaList(Long pointId) {
        synchronized (this) {
            if (point_MultimediaListQuery == null) {
                QueryBuilder<Multimedia> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.PointId.eq(null));
                point_MultimediaListQuery = queryBuilder.build();
            }
        }
        Query<Multimedia> query = point_MultimediaListQuery.forCurrentThread();
        query.setParameter(0, pointId);
        return query.list();
    }

}
